import { columns } from './index.const';
import ElEditable from '@components/el-editable';
export default {
  components: {
    ElEditable
  },
  inject: ['apiMMallWeb'],
  data() {
    return {
      value1: '',
      //日期限制
      pickerOptions0: {
        disabledDate(time) {
          return time.getTime() > Date.now() - 8.64e7;
        }
      },
      pickerOptions1: {
        disabledDate: time => {
          return Date.now() - 8.64e7 < time.getTime() || time.getTime() < this.tableQuery.commitDateStart;
        }
      },
      //多条件查询订单
      tableQuery: {
        orderCode: '',
        orderStatus: '',
        commitDateEnd: '',
        commitDateStart: '',
        productLineCode: '',
        busModel: 1
      },
      columns: columns,

      fullscreen: false,
      delDialogVisible: false,
      errorMsg: [], //错误信息
      payload: [],
      orderIds: [], //批量删除
      options: [],
      //产品线查询
      list: [],
      loading: false,
      states: ['1', 'BK', 'BDABDJFN', '产品线'],
      //分页
      currentPage: 1,
      pageSize: 20,
      total: 0
    };
  },
  async created() {
    const data = await this.apiMMallWeb.OrderDetailListOrderV1ApiPOST({ query: { busModel: 1 } });
    this.getPageInfo(data);
    s;
  },
  mounted() {
    this.list = this.states.map(item => {
      return { value: `${item}`, label: `${item}` };
    });
  },
  methods: {
    //获取分页数据
    getPageInfo(info) {
      this.payload = info.content;
      this.currentPage = info.number;
      this.total = info.totalElements;
      this.pageSize = info.size;
    },
    //分页
    handleSizeChange(val) {
      this.pageSize = val;
    },
    handleCurrentChange(val) {
      this.currentPage = val;
    },
    //产品线搜索框
    remoteMethod(query) {
      if (query !== '') {
        this.loading = true;
        setTimeout(() => {
          this.loading = false;
          this.options = this.list.filter(item => {
            return item.label.toLowerCase().indexOf(query.toLowerCase()) > -1;
          });
        }, 200);
      } else {
        this.options = [];
      }
    },
    // 重置
    queryFormReset() {
      this.$refs['queryForm'].resetFields();
      this.tableQuery.commitDateEnd = '';
      this.tableQuery.commitDateStart = '';
    },
    // 查询
    async queryFormQuery() {
      const query = {
        busModel: 1,
        commitDateEnd: this.tableQuery.commitDateEnd,
        commitDateStart: this.tableQuery.commitDateStart,
        orderCode: this.tableQuery.orderCode,
        orderStatus: this.tableQuery.orderStatus,
        page: this.currentPage,
        pageSize: this.pageSize,
        productLineCode: this.tableQuery.productLineCode
      };
      const data = await this.apiMMallWeb.OrderDetailListOrderV1ApiPOST({
        query: query
      });
      this.getPageInfo(data);
    },
    // 删除弹窗
    delDialog(scope) {
      this.delDialogVisible = true;
      this.orderIds.push(scope.orderId);
    },
    // 确认删除
    async delSure() {
      const data = await this.apiMMallWeb.DeleteOrderOrderV1ApiPOST({ orderIds: this.orderIds });
      this.delDialogVisible = false;
      const res = await this.apiMMallWeb.OrderDetailListOrderV1ApiPOST({ query: {} });
      this.getPageInfo(data);
    },
    // 取消删除
    concelDel() {
      this.delDialogVisible = false;
    },
    //编辑
    async editGo(scope) {
      this.$router.push({
        path: '/other-order/long/add',
        query: {
          id: scope.orderId,
          detailid: scope.orderDetailId
        }
      });
    },
    //查看
    checkDetail(scope) {
      this.$router.push({
        path: '/other-order/long/detail',
        query: {
          id: scope.orderId
        }
      });
    }
  }
};
